<div class="row">
    <div class="col-lg-9">
        <div class="card">
            <div class="card-body">
                <div class="table-responsive">
                    <form method="post" id="form-list">
                        <input type="hidden" name="action_type">
                        <input type="hidden" name="category_id">
                        <input type="hidden" name="delete_ategory_id">
                        <table class="table">
                            <thead>
                            <tr>
                                <th>分类</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            foreach ($categoryarticle as $item) {
                                ?>
                                <tr>
                                    <td><?php echo $item['categoryname']; ?></td>
                                    <td><?php echo $item['createtime']; ?></td>
                                    <td>
                                        <button type="button" class="btn btn-primary btn-sm m-l-5"
                                                onclick="edit(<?php echo $item['category_id']; ?>)">编辑
                                        </button>
                                        <button type="button" onclick="del(<?php echo $item['category_id']; ?>)" class="btn btn-danger btn-sm m-l-5">删除</button>
                                    </td>
                                </tr>
                                <?php
                            }
                            ?>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-3">
        <?php
        if(isset($editcategory)){
            ?>
            <div class="card">
                <div class="card-title">
                    编辑分类
                </div>
                <div class="card-body">
                    <form method="post" id="form-edit" action="index.php?r=post/categoryfiles">
                        <input type="hidden" name="action_type" value="saveedit">
                        <input type="hidden" name="category_id" value="<?php echo $editcategory['category_id']; ?>">
                        <div class="form-group">
                            <label>分类</label>
                            <input type="text" class="form-control" name="category" value="<?php echo $editcategory['categoryname']; ?>" minlength="1" placeholder="分类">
                        </div>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </form>
                </div>
            </div>
            <?php
        }else{
            ?>
            <div class="card">
                <div class="card-title">
                    新增分类
                </div>
                <div class="card-body">
                    <form method="post" id="form-edit">
                        <input type="hidden" name="action_type" value="save">
                        <div class="form-group">
                            <label>分类</label>
                            <input type="text" class="form-control" name="category" minlength="1" placeholder="分类">
                        </div>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </form>
                </div>
            </div>
            <?php
        }
        ?>

    </div>
    <!-- /# column -->
</div>
<!-- /# row -->
<script>
    function edit(category_id) {
        $("input[name=action_type]").val("edit");
        $("input[name=category_id]").val(category_id);
        $("#form-list").attr("action","index.php?r=post/categoryfiles");
        $("#form-list").submit();
    }
    function del(category_id) {
        $("input[name=action_type]").val("del");
        $("input[name=delete_ategory_id]").val(category_id);
        $("#form-list").attr("action","index.php?r=post/categoryfiles");
        $("#form-list").submit();
    }
</script>